import axios from 'axios'
import { applicationId } from '@/app.config.ts'

const ax = axios.create({
  baseURL: 'https://api.unsplash.com/',
  timeout: 30000,
  withCredentials: false
})

ax.interceptors.request.use(config => {
  if (config.url && config.url.includes('?')) {
    config.url = `${config.url}&client_id=${applicationId}`
  } else {
    config.url = `${config.url}/?client_id=${applicationId}`
  }

  return config
})

export default {
  // collection ids
  // 770997, 1005812, 1466596, 632279

  listCollectionsPhotos: (params = { page: 1, per_page: 20 }) =>
    ax.get(`/collections/632279/photos`, { params }),
  listRandomPhotos: (params = { count: 20, w: 800, h: 600 }) =>
    ax.get('/photos/random', { params })
}
